package com.nick.spring.dao;

import com.nick.spring.model.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;

@Repository("jdbcUserDao")
public class UserDao implements IuserDao{

    private JdbcTemplate jdbcTemplate;

    @Resource
    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public void add(User user) {
        this.jdbcTemplate.update(
                "insert into user_table (username, pass) values (?,?)",
                user.getUsername(), user.getPass());
    }

    public void update(User user) {
        this.jdbcTemplate.update(
                "update user_table set username = ?,pass=?  where id = ?",
                user.getUsername(), user.getPass(),user.getId());
    }

    public void delete(int id) {
        this.jdbcTemplate.update("delete from user_table where id = ?", id);
    }

    public User load(int id) {
        return null;
    }

    public List<User> list() {
        return null;
    }
}
